<%@ page language="java" import="java.util.*, java.text.*,com.zjut.an.util.tools.*,com.zjut.zs.util.tools.*,com.zjut.an.util.tools.*,com.zjut.an.util.system.*,
com.zjut.zs.user.manager.*, com.zjut.zs.user.dao.*,com.zjut.zs.userstatus.manager.*, com.zjut.zs.userstatus.dao.*,com.zjut.zs.applyview.manager.*, com.zjut.zs.applyview.dao.*,
com.zjut.zs.userinfo.manager.*, com.zjut.zs.userinfo.dao.*,com.zjut.an.config.manager.*, com.zjut.an.config.dao.*,com.zjut.an.acquisitionhistory.dao.*,com.zjut.an.acquisitionhistory.manager.*,
com.zjut.zs.exampage.manager.*, com.zjut.zs.exampage.dao.*" pageEncoding="utf-8"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">  
<meta name="renderer" content="webkit"> 
<title></title>

<link href="../plugins/assets/plugins/bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css"/>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script src='../plugins/assets/plugins/jquery-3.5.1.min.js'></script>
<script src="js/jquery.qrcode-0.6.0.min.js"></script>
<script src="js/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript">
function printHtml(html) {
	var bodyHtml = document.body.innerHTML;
	document.body.innerHTML = html;
	window.print();
	document.body.innerHTML = bodyHtml;
}
function onprint() {
	var html = $("#container").html();
	printHtml(html);
}
</script>
</head>

<body>
<jsp:include page="zs_uservalidate.jsp" flush="true"/>
<%
if (session.getAttribute("zsUser") == null&&session.getAttribute("admin") == null&&session.getAttribute("user") == null) {
	out.print("<script>alert('由于长时间未操作，系统已经自动注销，请重新登陆');</script>");
	out.print("<script>top.window.location='main.jsp';</script>");
} else {
AnAcquisitionHistoryManager acmanager = (AnAcquisitionHistoryManager) SpringContextUtil.getBean("AnAcquisitionHistoryManager");
AnConfigManager anconfig = (AnConfigManager) SpringContextUtil.getBean("AnConfigManager");
ZsHTMLCreat html = (ZsHTMLCreat) SpringContextUtil.getBean("ZsHTMLCreat");
ZsUserStatusManager usmanager = (ZsUserStatusManager) SpringContextUtil.getBean("ZsUserStatusManager");
ZsUserinfoManager uimanager = (ZsUserinfoManager) SpringContextUtil.getBean("ZsUserinfoManager");
ZsUserManager umanager = (ZsUserManager) SpringContextUtil.getBean("ZsUserManager");
ZsExamPageManager epmanager = (ZsExamPageManager) SpringContextUtil.getBean("ZsExamPageManager");
ZsApplyViewManager amanager = (ZsApplyViewManager) SpringContextUtil.getBean("ZsApplyViewManager");
StringUtil Stringutil = (StringUtil) SpringContextUtil.getBean("StringUtil");
ZsUser user = null;
if(session.getAttribute("admin")!=null && request.getParameter("usId")!=null) {
	String usId = request.getParameter("usId");
	user = umanager.getData(usId);
} else if (session.getAttribute("zsUser")!=null) {
	user = umanager.getData(((ZsUser)session.getAttribute("zsUser")).getUsId());
} 

ZsUserinfo userinfo = new ZsUserinfo();
ZsExamPage exampage = new ZsExamPage();

ZsUserStatus userstatus = new ZsUserStatus();
if (user!=null) {
	userinfo.setZsUser(user);
	userinfo = (ZsUserinfo)uimanager.getDataByInstance(1,1,null,null,userinfo).getObjects().get(0);
	
	userstatus.setZsUser(user);
	userstatus = (ZsUserStatus)usmanager.getDataByInstance(1,1,null,null,userstatus).getObjects().get(0);
	if (null != userstatus.getExId()) {
		exampage = epmanager.getData(userstatus.getExId());
	}
}

//String receiveno = user.getUsNo();

ZsApplyView appview = amanager.getData(user.getUsId());
ZsApplyView topview = new ZsApplyView();
topview.setInZymc01(appview.getInZymc01());
topview.setTestNo("0");
List topviewlist = amanager.getDataByInstance(1,10000,"testNo", "asc", topview).getObjects();

 %>
	<div class="place" style="margin-top:0;">
    <span>位置：</span>
    <ul class="placeul">
    <li><a href="#">首页</a></li>
    <li><a href="#"><%=anconfig.getSingleConfigInfoByName("准考证名称") %></a></li>
    </ul>
    </div>
    
    <%if (session.getAttribute("admin") != null) {//准考证单独打印模块
    	if ("do".equals(request.getParameter("action")) && null!=userstatus.getZsUser()) {//尚未编号才能再次编号
    		userstatus.setExId(Integer.parseInt(request.getParameter("exId")));
    		exampage = epmanager.getData(Integer.parseInt(request.getParameter("exId")));
    		if(Stringutil.isEmpty(userstatus.getTestNo())) {
	    		System.out.println("################################");
	    		//ZsUserinfo info = usmanager.getTestNoOrder(user);//******生成专业顺序号******//
   				AnAcquisitionHistory anac = new AnAcquisitionHistory();
				anac.setAcId(userstatus.getZsUser().getUsId());
				anac.setTitle(appview.getUsName());
				anac.setDescription(appview.getInZymc01());
				anac.setChannelUrl("现场准考证编号");
				anac.setContentUrl(userstatus.getUsIdcard());
				acmanager.saveHistory(anac);
				int place = acmanager.getDataPlaceById(anac);//取出专业的排序号
				userinfo.setInPinying(String.valueOf(place));
				uimanager.updateData(userinfo);//保存专业顺序号
				
				anac.setDescription(null);
				place = acmanager.getDataPlaceById(anac);//取出总的的排序号 
				String no = anconfig.getSingleConfigInfoByName("准考证编号前缀")+usmanager.getStringNo(place);//生成准考证编号并保存
				userstatus.setTestNo(no);
				usmanager.updateData(userstatus);	
	    		appview = amanager.getData(user.getUsId());//重新读取对象
    		} else {
    			out.print("<script>alert('准考证编号已经分配，不能重新生成专业顺序号');</script>");
    		}
    	} 
    %>
    <form id="ff" name="add" role="form" class="form-horizontal" action="zs_examprint_zjsf.jsp" method="post"> 
	<div class="form-group">  
	<ul class="forminfo">
		<li class="clear"><label>准考证打印<b>*</b></label></li>
		<% 
			ZsExamPage expages = new ZsExamPage();
			expages.setExType("准考证");
			List list = epmanager.getDataByInstance(1,100,null,null,expages).getObjects();
			for (int i=0; i<list.size(); i++){
				expages = (ZsExamPage)list.get(i);
			 %>							 
				<li>
				<input type="radio" name="exId" id="exId" value="<%=expages.getExId() %>" checked> 
				<%=expages.getExTitle() %>
				</li>						 
			<%} %>
		<li class="clear"><label>&nbsp;</label>
		<input id="usId" name="usId" type="text" class="dfinput" value="<%=user.getUsId() %>"  style="display:none;"/>
		<input id="action" name="action" type="text" class="dfinput" value="do"  style="display:none;"/>
		<input class="btn btn-primary btn-sm" onclick="creat();" class="btn btn-default btn-xs btn-success" value="生成准考证">
		</li>
		<li class="clear"><label>&nbsp;</label>当前准考证尚未编号才能进行单独编号，单独编号从目前已编号中取最大加1。已经编号不能再次编号。</li>
	</ul>
    </div>
    </form>
    <%} %>
    <li><div class="xline"></div></li>
    <input type="button" onclick="onprint()" value="打印" class="btn btn-primary btn-sm" style="margin:20px;"/>
    <div id="container" class="container" style="width:1000px;">
   
    <%
    if (null!=exampage.getExId()) {
    	String content = exampage.getExContent().replace("$usName$", appview.getUsName())
    			.replace("$usIdcard$", html.getInputString(appview.getUsIdcard()))
    	    	.replace("$usEmail$", html.getInputString(appview.getUsEmail()))
    	    	.replace("$usMobile$", html.getInputString(appview.getUsMobile()))
    	    	.replace("$testNo$", html.getInputString(appview.getTestNo()))
    	    	.replace("$column1$", html.getInputString(appview.getColumn1()))
    	    	.replace("$column2$", html.getInputString(appview.getColumn2()))
    	    	.replace("$column3$", html.getInputString(appview.getColumn3()))
    	    	.replace("$column4$", html.getInputString(appview.getColumn4()))
    	    	.replace("$column5$", html.getInputString(appview.getColumn5()))
    	    	.replace("$column6$", html.getInputString(appview.getColumn6()))
    	    	.replace("$column7$", html.getInputString(appview.getColumn7()))
    	    	.replace("$column8$", html.getInputString(appview.getColumn8()))
    	    	.replace("$column9$", html.getInputString(appview.getColumn9()))
    	    	.replace("$column10$", html.getInputString(appview.getColumn10()))
    	    	.replace("$inZydm01$", html.getInputString(appview.getInZydm01()))
    	    	.replace("$inZydm02$", html.getInputString(appview.getInZydm02()))
    	    	.replace("$inZydm03$", html.getInputString(appview.getInZydm03()))
    	    	.replace("$inZydm04$", html.getInputString(appview.getInZydm04()))
    	    	.replace("$inZydm05$", html.getInputString(appview.getInZydm05()))
    	    	.replace("$inZydm06$", html.getInputString(appview.getInZydm06()))
    	    	.replace("$inZydm07$", html.getInputString(appview.getInZydm07()))
    	    	.replace("$inZydm08$", html.getInputString(appview.getInZydm08()))
    	    	.replace("$inZydm09$", html.getInputString(appview.getInZydm09()))
    	    	.replace("$inZydm10$", html.getInputString(appview.getInZydm10()))
    	    	.replace("$inZymc01$", html.getInputString(appview.getInZymc01()))
    	    	.replace("$inZymc02$", html.getInputString(appview.getInZymc02()))
    	    	.replace("$inZymc03$", html.getInputString(appview.getInZymc03()))
    	    	.replace("$inZymc04$", html.getInputString(appview.getInZymc04()))
    	    	.replace("$inZymc05$", html.getInputString(appview.getInZymc05()))
    	    	.replace("$inZymc06$", html.getInputString(appview.getInZymc06()))
    	    	.replace("$inZymc07$", html.getInputString(appview.getInZymc07()))
    	    	.replace("$inZymc08$", html.getInputString(appview.getInZymc08()))
    	    	.replace("$inZymc09$", html.getInputString(appview.getInZymc09()))
    	    	.replace("$inZymc10$", html.getInputString(appview.getInZymc10()))
    	    	.replace("$scColumn1$", html.getInputString(appview.getScColumn1()))
    	    	.replace("$scColumn2$", html.getInputString(appview.getScColumn2()))
    	    	.replace("$scColumn3$", html.getInputString(appview.getScColumn3()))
    	    	.replace("$scColumn4$", html.getInputString(appview.getScColumn4()))
    	    	.replace("$scColumn5$", html.getInputString(appview.getScColumn5()))
    	    	.replace("$scColumn6$", html.getInputString(appview.getScColumn6()))
    	    	.replace("$scColumn7$", html.getInputString(appview.getScColumn7()))
    	    	.replace("$scColumn8$", html.getInputString(appview.getScColumn8()))
    	    	.replace("$scColumn9$", html.getInputString(appview.getScColumn9()))
    	    	.replace("$scColumn10$", html.getInputString(appview.getScColumn10()))
    	    	.replace("$inXb$", html.getInputString(appview.getInXb()))
    	    	.replace("$inMz$", html.getInputString(appview.getInMz()))
    	    	.replace("$inZzmm$", html.getInputString(appview.getInZzmm()))
    	    	.replace("$usBmxh$", html.getInputString(appview.getUsBmxh())) 
    	    	.replace("$inKslb$", html.getInputString(appview.getInKslb()))
    	    	.replace("$inLxdh$", html.getInputString(appview.getInLxdh()))
    	    	.replace("$inLxdh2$", html.getInputString(appview.getInLxdh2()))
    	    	.replace("$inByxxmc$", html.getInputString(appview.getInByxxmc()))
    	    	.replace("$testNoOrder$", html.getInputString(appview.getInPinying()))
    	    	.replace("$receiveno$", user.getUsNo());
    	content = content.replace("src=\"inPhoto\"", "src='../photo/"+html.getInputString(user.getUsIdcard())+".jpg' ");   	
	    out.print(content);
    } else {
    	out.print("尚未分配准考证");
    }
    %>
	</div>
<script>
$("#ewcode1").attr("src","http://qr.topscan.com/api.php?text=<%=anconfig.getSingleConfigInfoByName("网站域名") %>/admin/zsApplyViewStatus.jsp?usId=<%=user.getUsId()%>&localStatusType=single"); 
$("#ewcode2").attr("src","http://qr.topscan.com/api.php?text=<%=anconfig.getSingleConfigInfoByName("网站域名") %>/admin/zsApplyViewEdit.jsp?usId=<%=user.getUsId()%>"); 



function creat(){
	var ti = myRandom(1000,5000);
	alert('延迟'+ti+'毫秒生成准考证');
    setTimeout("mooy()",ti);
}
function mooy(){
	var ff=document.getElementById('ff');
	ff.submit();
}

function myRandom(begin,end){
    var num = Math.round(Math.random()*(end-begin)+begin);
    return num;
}
</script>

<%} %>
</body>
</html>
